﻿namespace QuickMail.View.Controls
{
    using QuickMail.BusinessLogic;
    using QuickMail.DataModels;
    using QuickMail.Properties;

    /// <summary>
    /// Standart settings control to connect to the mail.
    /// </summary>
    public partial class StandartConnectSettings
    {
        public StandartConnectSettings()
        {
            InitializeComponent();
            SetCurrentTranslate();
        }

        /// <summary>
        /// Sets the current translation for form elements.
        /// </summary>
        private void SetCurrentTranslate()
        {
            //FullNameTextBlock.Text = StaticFields.Lang.ConnectSettingsWindow.FullName;
            //FullNameTextBox.ToolTip = StaticFields.Lang.ConnectSettingsWindow.FullNameTt;
            EmailTextBlock.Text = StaticFields.Lang.ConnectSettingsWindow.Email;
            EmailTextBox.ToolTip = StaticFields.Lang.ConnectSettingsWindow.EmailTt;
            PasswordTextBlock.Text = StaticFields.Lang.ConnectSettingsWindow.Password;
            PasswordTextBlock.ToolTip = StaticFields.Lang.ConnectSettingsWindow.PasswordTt;
        }

        /// <summary>
        /// Loading settings in fields of form
        /// </summary>
        public void LoadSettings()
        {
            //FullNameTextBox.Background = EmailTextBox.Background = StaticFields.NormalColorBrush;

            //FullNameTextBox.Text = Settings.Default.FullName;
            EmailTextBox.Text = Settings.Default.GetEmail;
            UserPasswordBox.Password = CryptWorker.Decrypt(Settings.Default.GetPassword);
        }

        /// <summary>
        /// Checks the correctness of input fields.
        /// </summary>
        /// <returns>true - correct, false - incorrect</returns>
        public bool CheckingFields()
        {
            //FullNameTextBox.Background = EmailTextBox.Background = StaticFields.NormalColorBrush;
            EmailTextBox.Background = StaticFields.NormalColorBrush;
            bool result = true;

            //if (string.IsNullOrEmpty(FullNameTextBox.Text.Trim()))
            //{
            //    FullNameTextBox.Background = StaticFields.ErrorColorBrush;
            //    FullNameTextBox.Focus();
            //    result = false;
            //}

            if (string.IsNullOrEmpty(EmailTextBox.Text.Trim()) ||
                !HelpWorker.IsValidMail(EmailTextBox.Text.Trim()))
            {
                EmailTextBox.Background = StaticFields.ErrorColorBrush;
                result = false;
            }

            return result;
        }
    }
}
